package com.ecs.core.utils;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.Texture;

public class JsonRegion{
	// 纹理相关字段
    public String texturePath = "";//纹理路径
    public int regionX = 0;
    public int regionY = 0;
    public int regionWidth = 0;
    public int regionHeight = 0;
	
	public static TextureRegion CreateRegion(JsonRegion jr,AssetManager assetManager){
		// 加载纹理区域
        Texture texture = assetManager.get(jr.texturePath, Texture.class);
        if (texture == null) {
            throw new NullPointerException("请先加载纹理: " + jr.texturePath);
        }

        return CreateRegion(jr,texture);
	}
	public static TextureRegion CreateRegion(JsonRegion jr,Texture texture){
		// 加载纹理区域
        return new TextureRegion(
            texture,
            jr.regionX,
            jr.regionY,
            jr.regionWidth,
            jr.regionHeight
        );
	}
}
